package com.example.autocode.utils;

import com.example.autocode.model.DataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataSourceUtils {

    private static volatile Connection connection;

    private DataSourceUtils() {}

    public static Connection getConnection() {
        return connection;
    }

    public static Boolean init(DataSource dataSource) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        connection = DriverManager.getConnection(dataSource.getUrl(), dataSource.getRoot(), dataSource.getPassword());
        return connection != null;
    }

}
